﻿using Codinlab.CustomClass.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Codinlab.CustomClass.Handlers {
    public class CustomClassPartHandler : ContentHandler {
        protected override void BuildDisplayShape(BuildDisplayContext context) {
            if (context.ContentItem.Has(typeof(CustomClassPart))) {
                var customClassPart = context.ContentItem.As<CustomClassPart>();
                if (!String.IsNullOrWhiteSpace(customClassPart.CssClass)) {
                    foreach (var cssClass in customClassPart.CssClass.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) {
                        context.Shape.Classes.Add(cssClass);
                    }
                }
            }

            base.BuildDisplayShape(context);
        }
    }
}